package com.kgc.scd.controller;


import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;

import com.kgc.scd.bean.OrderComment;
import com.kgc.scd.bean.OrderNotComment;
import com.kgc.scd.service.CommentService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created On : 2022/6/17.
 * <p>
 * Author     : hi
 * <p>
 * Description: 商品评论
 */

@Slf4j
@RestController
@Api(tags = "22、商品评论入口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/addComments")
    @RequestPermission
    @ApiOperation(value = "添加商品评论入口", notes = "根据商品号和订单号添加")
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "添加商品评论失败！")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commProid", value = "评价商品ID"),
            @ApiImplicitParam(name = "commContent", value = "评价内容"),
            @ApiImplicitParam(name = "commLevel", value = "评价级别（默认1:好评  2:中评 3:差评）"),
            @ApiImplicitParam(name = "orderId", value = "订单号")
    })
    public RequestResult<Object> addComment(@RequestParam String commProid ,
                                            @RequestParam String commContent,
                                            @RequestParam(value = "commLevel",defaultValue = "1") Integer commLevel,
                                            @RequestParam String orderId,
                                            @RequestUser UserAnno user){
        return  commentService.addComment(commProid,commContent,commLevel,orderId,user.getUserId());
    }


    @PostMapping("/superadditionn")
    @RequestPermission
    @ApiOperation(value = "添加商品追评评论入口", notes = "根据商品号和订单号添加")
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "追评失败！")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commProid", value = "评价商品ID"),
            @ApiImplicitParam(name = "commAdd", value = "追加评价内容"),
            @ApiImplicitParam(name = "orderId", value = "订单号")
    })
    RequestResult<Object> superaddition(@RequestParam String commProid,
                                        @RequestParam String orderId,
                                        @RequestParam String commAdd,
                                        @RequestUser UserAnno user){
        return  commentService.superaddition(commProid,orderId,commAdd, user.getUserId());
    }

    @RequestPermission
    @PostMapping("/FeedbackHistorys")
    @ApiOperation(value = "查看我的待评价记录", notes = "根据用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "查看待评价记录失败！")
    })
    RequestResult<PageSupport<OrderNotComment>> FeedbackHistory(@RequestUser UserAnno userAnno,
                                                         @RequestParam(value = "pageSize",defaultValue = "1")Integer pageSize,
                                                         @RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo) {
        return commentService.FeedbackHistory(userAnno.getUserId(),pageSize,pageNo);
    }

    @RequestPermission
    @PostMapping("/OrderCommentLists")
    @ApiOperation(value = "查看我的已评价记录", notes = "根据用户")
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "查看评价记录失败！")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commLevel", value = "评价级别（默认1:好评  2:中评 3:差评 4:所有）"),
            @ApiImplicitParam(name = "orderByDate", value = " 1:时间降序，0：时间升序")
    })
            // 1:好评 2：中评 3：差评 4:所有
    // 1:时间降序，0：时间升序
    RequestResult<PageSupport<OrderComment>> OrderCommentList(@RequestUser UserAnno userAnno,
                                                              @RequestParam(value ="commLevel",defaultValue = "4") Integer commLevel,
                                                              @RequestParam(value = "orderByDate",defaultValue = "0")Integer orderByDate,
                                                              @RequestParam(value = "pageSize",defaultValue = "1")Integer pageSize,
                                                              @RequestParam(value = "pageNo",defaultValue = "1")Integer pageNo){
        return commentService.OrderCommentList(userAnno.getUserId(),commLevel,orderByDate,pageSize,pageNo);
    }
}
